"""
统计访问对象
"""
from connector.driver import DatabaseDriver


def book_count_by_type(driver: DatabaseDriver):
    """
    查询各类别的图书数量
    SQL:
    SELECT b.bookTypeName, COUNT(a.id) AS count
    FROM t_book a INNER JOIN t_booktype b
    ON a.bookTypeId = b.id
    GROUP BY a.bookTypeId
    :return:
    [('计算机类2', 3), ('文学类', 2)]
    """
    return driver.query_all(
        f"SELECT b.cate_name, COUNT(a.book_id) AS count FROM book a INNER JOIN category b ON a.cate_id = b.cate_id GROUP BY a.cate_id")



